package com.colorlight.cloud.xm;

import com.colorlight.cloud.Util;
import com.colorlight.cloud.common.utils.HexUtil;
import com.colorlight.cloud.gateway.api.message.constraint.protocol.ProtocolType;
import com.colorlight.cloud.gateway.api.message.constraint.schedule.ScheduleActions;
import com.colorlight.cloud.gateway.api.message.convert.CommandConvert;
import com.colorlight.iot.proto.complete.entity.CompleteEntity;
import com.colorlight.iot.proto.complete.event.CompleteEvent;
import com.colorlight.iot.proto.grandshow.event.GrandShowEvent;
import com.google.protobuf.ByteString;
import com.google.protobuf.MessageLite;
import com.iot.proto.type.ProtocolSummationType;
import org.junit.jupiter.api.Test;

/**
 * @author Demon
 * @date 10/5/2024  上午10:17
 */
public class ToMsg {
	
	private ProtocolSummationType.NameStruct getNameStruct(ScheduleActions f) {
		
		ProtocolType protocolType = f.getProtocolType();
		String thisName = protocolType.getThisName();
		return ProtocolSummationType.NameStruct.valueOf(thisName);
	}
	
	@Test
	public void test_HB() {
		GrandShowEvent.HB.Builder builder = GrandShowEvent.HB.newBuilder();
		ByteString bytes = builder.build().toByteString();
		
		MessageLite convert = CommandConvert.convertMsg(bytes, "7777-888-999-999", 11111L,ProtocolSummationType.NameStruct.HBEvent);
		Util.printByteArray(convert.toByteArray());
		System.out.println(HexUtil.toHex(convert.toByteArray()));
		
	}
	
	@Test
	public void LocationUpload() {
		
		CompleteEvent.LocationUpload locationUpload = CompleteEvent.LocationUpload
				.newBuilder()
				.setLocation(
						CompleteEntity.Location
								.newBuilder()
								.setLongitude(0.111)
								.setLatitude(0.222)
								.setType(CompleteEntity.LocationType.BD09)
				)
				.build();
		
		byte[]  bytes= locationUpload.toByteArray();
		MessageLite convert = CommandConvert.convertMsg(ByteString.copyFrom(bytes), "7777-888-999-999", 11111L,ProtocolSummationType.NameStruct.LocationUploadEvent);
		byte[] bytes1 = convert.toByteArray();
		Util.printByteArray(bytes1);
		System.out.println(HexUtil.toHex(bytes1));
	}
	
}
